package s.k.gui.webtest.basetools;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class ListRemoveDuplicate {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List<String> removeDuplicateWithOrder(List<?> list) {

		Set set = new HashSet();

		List newList = new ArrayList();

		for (Iterator iter = list.iterator(); iter.hasNext();) {

			Object element = iter.next();

			if (set.add(element))

				newList.add(element);
		}
		return newList;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List<Field> removeDuplicateWithOrderByField(List<?> list) {

		Set set = new HashSet();

		List newList = new ArrayList();

		for (Iterator iter = list.iterator(); iter.hasNext();) {

			Object element = iter.next();

			if (set.add(element))

				newList.add(element);
		}
		return newList;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List<Method> removeDuplicateWithOrderByMethod(List<?> list) {

		Set set = new HashSet();

		List newList = new ArrayList();

		for (Iterator iter = list.iterator(); iter.hasNext();) {

			Object element = iter.next();

			if (set.add(element))

				newList.add(element);
		}
		return newList;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List<Class> removeDuplicateWithOrderByClass(List<?> list) {

		Set set = new HashSet();

		List newList = new ArrayList();

		for (Iterator iter = list.iterator(); iter.hasNext();) {

			Object element = iter.next();

			if (set.add(element))

				newList.add(element);
		}
		return newList;
	}

}
